-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: the position of _read() is wrong #38292
Conversation
Hi @helloyou2012, could you remove the merge commit from your branch? Merge commits tend to break the tooling, you can use node/doc/guides/contributing/pull-requests.md Lines 215 to 217 in 54322b8
|
@nodejs/streams |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is wrong? Can you please expand?
Can you please add a unit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs test and also a little unsure what exactly we are solving here. If I would guess:
- Currently
this.pos
could actually be larger than the file size, which is a little weird. - Currently
this.pos
is what we have requested, but necessarily what we have read.
@mcollina see this issue: #33940, this node/lib/internal/streams/readable.js Line 487 in d4f33f1
_read(n) multiple times with n= highWaterMark , but the bytesRead may be not equal to n , then the data will loss. Example:
|
The problem arised because current implementation assumed next position to start reading is node/lib/internal/fs/streams.js Lines 275 to 277 in d4f33f1
But in reality, it does not necessarily read node/lib/internal/fs/streams.js Line 246 in d4f33f1
As a result, some bytes in file may be skipped. The "assumed" reading is longer than the "actual". About the test, the issue occurred because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change could make sense. But we need a test.
Good question. I'm not sure I don't think I ever wrote such a test in Node - A good way to try is to take the test case from #33940 and to try to make a smaller isolated case from it (shorter interval and smaller watermark) @nodejs/fs |
I added test case. @ronag @benjamingr |
highWaterMark: hwm, | ||
start: cur | ||
}); | ||
stream.on('data', common.mustCallAtLeast((chunk) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this is a mustCAllAtLeast and not a mustCall?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mustCall is exact times, but this place will call at least 1 time not exact 1 time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if the test passes after this and fails in master
Also thank you for the meaningful contribution and working with us 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, hopefully the setInterval test would not fail in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Was wondering why this hasn't landed yet. Turns out it's my fault.
I think there is a problem on arm with the new test. @helloyou2012 |
Yes, the test timed out. I think it is better to set a time after which to exit safely. I will fix later. |
Removing the author ready label as there's still work to be done here. |
@helloyou2012 this still seems to have problems passing. Could you try and look at the CI failures? I started another CI just in case. |
It failed cause of |
This CI all passed. |
Landed in d826f6b |
Fixes: #33940 PR-URL: #38292 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Fixes: #33940 PR-URL: #38292 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Fixes: #33940 PR-URL: #38292 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Fixes: #33940 PR-URL: #38292 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Fixes: #33940 PR-URL: #38292 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Fixes: #33940 PR-URL: #38292 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Fixes: #33940